home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / ZIZ4LST.CPP < prev    next >
C/C++ Source or Header  |  1993-08-09  |  8KB  |  255 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    ziz4lst.cpp
  5. //   Title:    9 Digit ZIP Disc Interface
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class ZI_Z4_LIST.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <zi.hpp>
  41. #define USE_WIN_Z4_LIST
  42. #if OS_DOS
  43. #include <zid.hpp>
  44. #elif OS_WINDOWS
  45. #include <ziw.hpp>
  46. #else
  47. #include <zio.hpp>
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //   Description:    Default constructor
  53. //    Parameters:
  54. //       Returns:    
  55. //----------------------------------------------------------------------------
  56. FN_M ZI_Z4_LIST::ZI_Z4_LIST(SIZET cRecs, PRECID _precid)
  57. : ZN_WINDOW("WIN_Z4_LIST", ZN_LOAD_CENTER|ZN_LOAD_HELPBAR|ZN_LOAD_NO_SHOW)
  58. {
  59.     ZI_Z4_LIST::Initialize(CL_INIT_CLASS);
  60.     precid = _precid;
  61.     lRecords = (LONG)cRecs;
  62.     Setup();
  63. }
  64.  
  65.  
  66. //----------------------------------------------------------------------------
  67. //   Description:    Destructor
  68. //    Parameters:
  69. //       Returns:    
  70. //----------------------------------------------------------------------------
  71. FN_M ZI_Z4_LIST::~ZI_Z4_LIST()
  72. {
  73.     ZI_Z4_LIST::Destroy(FALSE);
  74.     Terminate();
  75. }
  76.  
  77.  
  78. //----------------------------------------------------------------------------
  79. //   Description:    Destroy object. Free any resources used by object.
  80. //                          Normally called by destructor.
  81. //                        Should allow multiple calls from various classes.
  82. //                        A class should almost always re-init its variables when 
  83. //                        it is destroyed to prevent accidents.
  84. //    Parameters:    fDestroyAll        Destroy parents also?
  85. //                                            Default is TRUE.
  86. //       Returns:    TRUE if successful.
  87. //----------------------------------------------------------------------------
  88. BOOL FN_M ZI_Z4_LIST::Destroy(BOOL fDestroyAll)
  89. {
  90.     ZI_Z4_LIST::Initialize(CL_INIT_CLASS_VARS);
  91.     if (fDestroyAll)                            // Destroy parent.
  92.         ZI_Z4_LIST_PARENT::Destroy(fDestroyAll);
  93.     return TRUE;
  94. }
  95.  
  96.  
  97. //----------------------------------------------------------------------------
  98. //   Description:    Initialize object. 
  99. //                          Normally called by constructor.
  100. //                        Should allow multiple calls from various classes.
  101. //    Parameters:    sInit        Initialization code. May be one of the following:
  102. //                                        CL_INIT_CLASS            Reset class variables and
  103. //                                                                    and dynamic allocations for
  104. //                                                                    this class only.
  105. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  106. //                                                                    this class only.
  107. //                                        CL_INIT_VARS            Reset class variables for
  108. //                                                                    this class only.
  109. //                                        CL_INIT_ALL                Initialize class and all 
  110. //                                                                    parent class, including
  111. //                                                                    dynamic memory allocation.
  112. //                                    Default is CL_INIT_ALL
  113. //       Returns:    TRUE if successful.
  114. //----------------------------------------------------------------------------
  115. BOOL FN_M ZI_Z4_LIST::Initialize(SHORT sInit)
  116. {
  117.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  118.         ZI_Z4_LIST_PARENT::Initialize(sInit);
  119.  
  120.     lCurrent = 0;
  121.     lRecords = 0;
  122.     precid = NULL;
  123.     return TRUE;
  124. }
  125.  
  126.  
  127. //----------------------------------------------------------------------------
  128. //   Description:    Set field values.
  129. //    Parameters:
  130. //       Returns:    TRUE if valid
  131. //----------------------------------------------------------------------------
  132. BOOL FN_M ZI_Z4_LIST::Query(PZN_VLIST_ELEM pzn_vlist_elem)
  133. {
  134.     pzn_vlist_elem->pszBuf = szFormat;
  135.     szFormat[0] = '\0';
  136.     if (!Z4_INQ::z4_file.Record(Z4_INQ::z4, precid[(SIZET)pzn_vlist_elem->lId]))
  137.         return FALSE;
  138.  
  139.     if (!Z4_INQ::z5_file.Find(Z4_INQ::z5, Z4_INQ::z4.szZip5)
  140.     || !Z4_INQ::cs_file.Best(Z4_INQ::cs, Z4_INQ::z5, Z4_INQ::z4.szLastLine))
  141.         memset(&Z4_INQ::cs, 0, sizeof(Z4_INQ::cs));
  142.  
  143.     CHAR szSecRange[30];
  144.     CHAR szPriRange[30];
  145.     CHAR szAddr2[MAX_ADDR_LINE+5];
  146.     CHAR szLastLine[MAX_ADDR_LINE+5];
  147.  
  148.     Z4_STANDARDIZE::SecRangeDisplay(szSecRange, Z4_INQ::z4);
  149.     Z4_STANDARDIZE::PriRangeDisplay(szPriRange, Z4_INQ::z4);
  150.     Z4_STANDARDIZE::Addr2Display(szAddr2, Z4_INQ::z4, "", "");
  151.     Z4_STANDARDIZE::LastLineDisplay(szLastLine, Z4_INQ::cs, Z4_INQ::z4.szZip5, Z4_INQ::z4.szAddonLo);
  152.     sprintf(szFormat, "\t%s\t%s\n\t%s\t%s\n\t%s",
  153.         Z4_INQ::z4.szSecName,
  154.         szSecRange,
  155.         szPriRange,
  156.         szAddr2,
  157.         szLastLine);
  158.     return TRUE;
  159. }
  160.  
  161.  
  162. //----------------------------------------------------------------------------
  163. //   Description:    Event monitor function.
  164. //    Parameters:    msg        Event code
  165. //                        pv1            Data pointer 1
  166. //                        pv2            Data pointer 2
  167. //       Returns:    Event code
  168. //----------------------------------------------------------------------------
  169. ZN_MSG FN_M ZI_Z4_LIST::User(ZN_MSG msg, PVOID pv1, PVOID pv2)
  170. {
  171.     switch (msg)
  172.         {
  173.         case ZN_MSG_INIT:
  174.             return msg;
  175.  
  176.         case ZN_MSG_TERMINATE:
  177.             return msg;
  178.  
  179.         case ZN_MSG_VLIST_INIT:
  180.             {
  181. static int aiTabstops[] = { 2, 45, 0, 2, 24, 0, 2, 0, 0 };
  182.  
  183.             PZN_VLIST_INIT pzn_vlist_init = (PZN_VLIST_INIT)pv2;
  184.             pzn_vlist_init->lElems = lRecords;
  185.             pzn_vlist_init->fs = ZN_VLIST_SINGLE|ZN_VLIST_TITLE;
  186.             pzn_vlist_init->aiTabstops = aiTabstops;
  187.             }
  188.             return msg;
  189.  
  190.         case ZN_MSG_VLIST_TITLE:
  191.             {
  192.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  193.             pzn_vlist_elem->pszBuf = szFormat;
  194.             strcpy(szFormat, "\tName\n\tRange\tStreet\n\tCity/State/ZIP");
  195.             }
  196.             return msg;
  197.         }
  198.     if (IsError())                                // Error condition
  199.         return msg;
  200.     switch (msg)
  201.         {
  202.         case ZN_MSG_VLIST_QUERY:
  203.             Query((PZN_VLIST_ELEM)pv2);
  204.             break;
  205.  
  206.         case ZN_MSG_VLIST_SELECT:
  207.             {
  208.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  209.             lCurrent = pzn_vlist_elem->lId;
  210.             }
  211.             // Fall through
  212.         case ZN_MSG_VLIST_CURRENT:
  213.             {
  214.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  215.             LONG lRec = pzn_vlist_elem->lId;
  216.             sprintf(szFormat, "Record %ld of %ld", lRec + 1, lRecords);
  217.             SetHelp(szFormat);
  218.             }
  219.             break;
  220.  
  221.         case ZN_MSG_VLIST_DBL_CLK:
  222.             {
  223.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  224.             lCurrent = pzn_vlist_elem->lId;
  225.             }
  226.         case TB_SELECT:
  227.             SendMessage(ZiMainWindow(), ZI_MSG_SELECT, (PVOID)lCurrent);
  228.             Close();
  229.             break;
  230.  
  231.         case ZN_MSG_HELP:
  232.             return ZN_MSG_NO_HELP;
  233.  
  234.         case TB_GOTO:
  235.             ZI_GOTO::Goto(FID(Number()), lRecords, 1, lCurrent + 1);
  236.             break;
  237.  
  238.         case ZI_MSG_GOTO:
  239.             SetVlistPos(((LONG)pv1) - 1);
  240.             break;
  241.  
  242.         case TB_CLOSE:
  243.             Close();
  244.             break;
  245.  
  246.         case TB_HELP:
  247.             NotDone();
  248.             break;
  249.         }
  250.     return msg;
  251. }
  252. //----------------------------------------------------------------------------
  253. //------------------------------- End of File --------------------------------
  254. //----------------------------------------------------------------------------
  255.